package com.woniu.controller;/*
 *
 * @author   米雷
 * @Description
 * @Date:create in 16:44 2020-04-08
 *
 * */

import com.woniu.dto.FriendName;
import com.woniu.pojo.Friends;
import com.woniu.service.FriendService;
import com.woniu.userLog.LogPoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/friend")
@Api(tags = "好友")
@CrossOrigin(allowCredentials = "true", maxAge = 3600)
public class FriendController {


    @Autowired
    FriendService friendService;

    @GetMapping("/getFriend")
    @ApiOperation("查看好友列表")
    @ResponseBody
    @LogPoint("用户查看好友列表")
    public List<FriendName> getFridends(Long id)
    {
        List<FriendName> friends = friendService.getFriend(id);
        for (int i = 0; i < friends.size(); i++)
        {
            System.out.println(friends.get(i));
        }
        return friends;
    }

    @GetMapping("/addFriend")
    @ApiOperation("增加好友")
    @ResponseBody
    @LogPoint("用户增加好友")
    public String addFridends(Long uid,Long fid)
    {
        String res = friendService.addFriend(uid,fid);
        return res;
    }

    @GetMapping("/delFriend")
    @ApiOperation("删除好友")
    @ResponseBody
    @LogPoint("用户删除好友")
    public String delFridends(Long uid,Long fid)
    {
        String res = friendService.delFriend(uid,fid);
        return res;
    }
}
